package com.vg.classSample;

import android.graphics.Bitmap;
import android.os.Handler;

import com.kdstudio.network.URLCachePolicy;
import com.kdstudio.network.URLRequest;
import com.kdstudio.network.URLRequestDelegate;
import com.kdstudio.network.reponse.URLBitmapResponse;
import com.vg.Adapter.adapter_Friend;

public class Friend {

	private String status;
	private String url_img;
	private String name;
	private Bitmap image;
	Handler mhHandler;
	int Res;
	//private SampleAdapter adapter;
	adapter_Friend adapter;

	public String getUrl_img() {
		return url_img;
	}
	public Friend() {
		super();
	}
	public void setUrl_img(String url_img) {
		this.url_img = url_img;
	}
	public Friend(String url,String name) {
		
		this.url_img = url; 
		this.name=name;
		//adapter.notifyDataSetChanged();
		
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Bitmap getImage() {
		return image;
	}
	public void setImage(Bitmap image) {
		this.image = image;
	}
	
	
	
	public void loadImage() {
		URLRequest request=new URLRequest(getUrl_img(), new RequestDelegate());
		request.setReponse(new URLBitmapResponse());
		request.setCachePolicy(URLCachePolicy.MEMCACHE);
		request.send();
	}
	
	
	
	public int getRes() {
		return Res;
	}
	public void setRes(int res) {
		Res = res;
	}



	private class RequestDelegate extends URLRequestDelegate
	{
		@Override
		public void onRequestReponse(final URLRequest httpRequest) {
			 mhHandler=new Handler();
			mhHandler.post(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					URLBitmapResponse reponse=(URLBitmapResponse)httpRequest.getReponse();
					setImage(reponse.bitmap);
					//adapter.notifyDataSetChanged();
					
				}
			});
			// TODO Auto-generated method stub
			
		}
		
		//anh hien thi khi timeout
		@Override
		public void onRequestError(URLRequest httpRequest, Throwable error) {
			// TODO Auto-generated method stub
			
		}
		
		//chay tu dau la anh gi khi load xong se thay doi
		@Override
		public void onRequestStart(URLRequest httpRequest) {
			// TODO Auto-generated method stub
			super.onRequestStart(httpRequest);
		}
	}
	

}
